import type { Stats } from "fs";
import fs from "fs/promises";

export async function exists(path: string): Promise<Stats | null> {
  try {
    return await fs.stat(path); // 能获取 stats，说明存在
  } catch {
    return null; // 抛错说明不存在
  }
}

export async function isFile(path: string) {
  const stat = await exists(path);
  return stat ? stat.isFile() : false;
}

export async function isDirectory(path: string) {
  const stat = await exists(path);
  return stat ? stat.isDirectory() : false;
}
